package agentea;

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import agentzia.AgenteInterfazea;
import agentzia.Irteerak;

public class Agente extends UnicastRemoteObject implements AgenteInterfazea {

    protected Agente() throws RemoteException {

    }

    private static final long serialVersionUID = 1L;

    public Irteerak[] getIrteerak() throws RemoteException {
        Irteerak[] irteerak;
        irteerak = AgenteDatuBasea.instance().getIrteerak();
        return irteerak;
    }

    public void libratuPlazak(int irteeraKodea, int plazaKopurua)
            throws RemoteException {
        // TODO Auto-generated method stub
        AgenteDatuBasea.instance().libratuPlazak(irteeraKodea, plazaKopurua);
    }

    public int okupatuPlazak(int irteeraKodea, int plazaKopurua)
            throws RemoteException {
        return AgenteDatuBasea.instance().okupatuPlazak(irteeraKodea,
                plazaKopurua);
    }

    public static void main(String[] args) {
        try {

            if (System.getSecurityManager() == null) {
                System.setProperty("java.security.policy", "rmi.policy");
                System.setSecurityManager(new RMISecurityManager());
            }
            try {
                java.rmi.registry.LocateRegistry.createRegistry(1099);
            } catch (Exception e) {
                System.out
                        .println(e.toString()
                                + "\nSuposatzen dugu errorea dela rmiregistry aurretik jaurti delako ");
            }
            Naming.rebind("agenteRmi", new Agente());
            System.out.println("Urruneko objektua prest dago.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
